<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>金额变更记录</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary: #4a6cf7;
            --secondary: #6a11cb;
            --success: #25d366;
            --danger: #ff4757;
            --warning: #ffa502;
            --light: #f8f9fa;
            --dark: #2c3e50;
            --gray: #7a7e8c;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f0f4f8;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* 上层样式 - 顶部导航栏 */
        .top-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 30px;
            background-color: #ffffff;
            box-shadow: 0 2px 15px rgba(0,0,0,0.1);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .back-btn {
            background-color: var(--primary);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .back-btn:hover {
            background-color: #3a5ce0;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(74, 108, 247, 0.3);
        }

        .page-title {
            font-size: 24px;
            font-weight: 700;
            color: var(--dark);
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
        }

        .username {
            font-weight: 600;
            color: var(--dark);
            padding: 8px 15px;
            border-radius: 20px;
            background-color: #f0f4f8;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        /* 内容区域样式 */
        .content-container {
            flex: 1;
            padding: 30px;
            max-width: 1200px;
            width: 100%;
            margin: 0 auto;
            display: flex;
            flex-direction: column;
            gap: 30px;
        }

        .stats-summary {
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
        }

        .stat-card {
            background: white;
            border-radius: 16px;
            padding: 20px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.05);
            flex: 1;
            min-width: 200px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .stat-title {
            font-size: 16px;
            color: var(--gray);
            margin-bottom: 10px;
        }

        .stat-value {
            font-size: 28px;
            font-weight: 700;
        }

        .income {
            color: var(--success);
        }

        .expense {
            color: var(--danger);
        }

        .records-container {
            background-color: white;
            border-radius: 16px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.05);
            overflow: hidden;
        }

        .section-header {
            background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
            color: white;
            padding: 20px 30px;
            font-size: 20px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .transaction-table {
            width: 100%;
            border-collapse: collapse;
        }

        .transaction-table th {
            background-color: #f8fafc;
            color: var(--dark);
            font-weight: 600;
            text-align: left;
            padding: 18px 25px;
            border-bottom: 2px solid #eef2f7;
        }

        .transaction-table td {
            padding: 16px 25px;
            border-bottom: 1px solid #eef2f7;
            color: var(--dark);
        }

        .transaction-table tr:hover {
            background-color: #f8fafc;
        }

        .transaction-id {
            font-weight: 500;
            color: var(--primary);
        }

        .transaction-date {
            color: var(--gray);
        }

        .transaction-amount.positive {
            color: var(--success);
            font-weight: 600;
        }

        .transaction-amount.negative {
            color: var(--danger);
            font-weight: 600;
        }

        .transaction-type {
            display: inline-block;
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 500;
        }

        .type-recharge {
            background-color: rgba(37, 211, 102, 0.15);
            color: var(--success);
        }

        .type-payment {
            background-color: rgba(255, 71, 87, 0.15);
            color: var(--danger);
        }

        .type-refund {
            background-color: rgba(255, 165, 2, 0.15);
            color: var(--warning);
        }

        /* 分页控件 */
        .pagination {
            display: flex;
            justify-content: center;
            padding: 30px;
            gap: 12px;
        }

        .pagination button {
            background-color: var(--primary);
            color: white;
            border: none;
            height: 40px;
            padding: 0 16px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 2px 6px rgba(74, 108, 247, 0.3);
        }

        .pagination button:hover:enabled {
            background-color: #3a5ce0;
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(74, 108, 247, 0.3);
        }

        .pagination button:disabled {
            background-color: #eef2f7;
            color: #cbd5e1;
            cursor: not-allowed;
            box-shadow: none;
        }


        /* 空状态 */
        .empty-state {
            padding: 50px 20px;
            text-align: center;
            color: var(--gray);
        }

        .empty-state i {
            font-size: 60px;
            margin-bottom: 20px;
            color: #cbd5e1;
        }

        .empty-state p {
            font-size: 18px;
            margin-top: 10px;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .top-bar {
                padding: 15px;
            }

            .page-title {
                font-size: 18px;
                left: 45%;
            }

            .content-container {
                padding: 15px;
            }

            .stats-summary {
                flex-direction: column;
            }

            .transaction-table {
                display: block;
                overflow-x: auto;
            }

            .username span {
                display: none;
            }
        }
    </style>
</head>
<body>
<!-- 上层：顶部导航栏 -->
<div class="top-bar">
    <!-- 返回按钮 -->
    <button class="back-btn" onclick="location.href='/clients/clientuserspace'">
        <i class="fas fa-arrow-left"></i> 返回
    </button>

    <!-- 页面标题 -->
    <div class="page-title">金额变更记录</div>

    <!-- 用户名 -->
    <div class="username">
        <i class="fas fa-user"></i>
        <span th:text="${user.username}">用户名</span>
    </div>
</div>

<!-- 下层：内容区域 -->
<div class="content-container">
    <!-- 统计摘要 -->
    <div class="stats-summary">
        <div class="stat-card">
            <div class="stat-title">总消费金额</div>
            <div class="stat-value income" th:text="'¥' + ${totalAmount}">¥0.00</div>
        </div>

        <div class="stat-card">
            <div class="stat-title">总消费次数</div>
            <div class="stat-value" th:text="${totalCount}">0</div>
        </div>
    </div>

    <!-- 交易记录表格 -->
    <div class="records-container">
        <div class="section-header">
            <i class="fas fa-file-invoice-dollar"></i>
            交易记录
        </div>

        <!-- 数据接口：后端需提供 List<Transaction> transactions -->
        <div th:if="${transactions != null and !transactions.isEmpty()}">
            <table class="transaction-table">
                <thead>
                <tr>
                    <th>交易单号</th>
                    <th>变更日期</th>
                    <th>变更金额</th>
                    <th>变更类型</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="tx : ${transactions}">
                    <td class="transaction-id" th:text="${tx.transactionId}">TX20230623001</td>
                    <td class="transaction-date" th:text="${tx.createdAt}">2023-06-23 14:30</td>
                    <td>
                                <span th:class="${tx.amount >= 0} ? 'transaction-amount positive' : 'transaction-amount negative'"
                                      th:text="${tx.amount} +'元'">
                                    ¥100.00
                                </span>
                    </td>
                    <td>
                        <span th:switch="${tx.type}" class="transaction-type">
                            <span th:case="'recharge'" class="type-recharge">充值</span>
                            <span th:case="'expense'" class="type-payment">消费</span>
                        </span>
                    </td>
                </tr>
                </tbody>
            </table>

            <!-- 空状态显示 -->
            <div class="empty-state" th:unless="${transactions != null and !transactions.isEmpty()}">
                <i class="fas fa-file-invoice"></i>
                <h3>暂无交易记录</h3>
                <p>您还没有任何金额变更记录</p>
            </div>
            <!-- 分页控件 -->
            <div class="pagination">
                <button th:disabled="${currentPage == 1}"
                        th:onclick="'location.href=\'/clients/clientpayhistory?page=' + (${currentPage} - 1) + '&size=8\''">上一页</button>

                <span th:text="'第 ' + ${currentPage} + ' 页 / 共 ' + ${totalPages} + ' 页'"></span>

                <button th:disabled="${currentPage == totalPages}"
                        th:onclick="'location.href=\'/clients/clientpayhistory?page=' + (${currentPage} + 1) + '&size=8\''">下一页</button>
            </div>

        </div>

    </div>
</div>

<script>
    // 简单的交互效果
    document.querySelectorAll('.transaction-table tr').forEach(row => {
        row.addEventListener('click', function() {
            this.classList.toggle('selected');
        });
    });
</script>
</body>
</html>